/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2024-02-01
 * Time: 22:10
 * https://www.nowcoder.com/share/jump/7745334641706796649390
 */


public class BM97 {
    public int[] solve(int n, int m, int[] a) {
        // 取余，减少循环交换
        m = m % n;
        // 首先先将数组整体逆置
        reverse(a, 0, n - 1);
        // 然后将前 m 个元素逆置
        reverse(a, 0, m - 1);
        // 最后将再剩余的元素逆置
        reverse(a, m, n - 1);
        return a;
    }

    public void reverse(int[] a, int l, int r) {
        while (l < r) {
            int tmp = a[r];
            a[r] = a[l];
            a[l] = tmp;
            l++;
            r--;
        }
    }

}







